package pl.myszon.wifimap;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.os.Bundle;
import android.view.MenuInflater;

public class MainActivity extends MapActivity {
    private LocationProvider locationProvider = null;
    private WiFiDetection wifiDetectionService = null;
    private MapController mapController = null;
    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
    
        locationProvider = new LocationProvider(this, new LocationUpdater());
        mapController = mapView.getController(); 
        mapController.setZoom(15);
        
        wifiDetectionService.addWiFiLocationListener(new WiFiLocationProvider());
        wifiDetectionService.startService(null);
    }

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
	
	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.mainmenu, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(android.view.MenuItem item) {
		switch(item.getItemId()) {
			case R.id.save:
				saveSelected();
			break;
			
			case R.id.options:
				optionsSelected();
			break;
			
			case R.id.exit:
				finish();
			break;
		
			default:
				return super.onOptionsItemSelected(item);
		}
		return true;
	}
	

	private void optionsSelected() {
		// TODO Auto-generated method stub
		
	}

	private void saveSelected() {
		// TODO Auto-generated method stub
		
	}


	class LocationUpdater implements IUserLocationUpdater {

		@Override
		public void updateMyLocation(GeoPoint location) {
			mapController.setCenter(location);
		}
	}
	
	class WiFiLocationProvider implements IWiFiLocationUpdater {

		@Override
		public void markNetworkOnMap(GeoPoint location, NetworkProtection protection) {
			//TODO 
		}
	}
}